<?php
require('system-config.php');

if ($_POST['token'])
	validateToken($_POST['token'], 'rewriterules.php', $_POST['action']);

switch ($action = $_POST['action']) {
	case 'delete':
		$home_path = get_home_path();
		unlink($home_path.'.htaccess');
		header('Location: rewriterules.php');
		exit();
		break;

	case 'write':
		$home_path = get_home_path();
		$rules = explode("\n", $wp_rewrite->mod_rewrite_rules());
		insert_with_markers($home_path.'.htaccess', 'Lyceum', $rules);
		header('Location: rewriterules.php');
		exit();
		break;

}

// ===========================================================================
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title><?php echo $site_title ?>: Lyceum System Settings: Rewrite Rules</title>

	<link rel="stylesheet" href="<?php echo LURL ?>/wp-admin/wp-admin.css" type="text/css" />
	<link rel="stylesheet" href="<?php echo LURL ?>/system-admin/lyceum.css" type="text/css" />

	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
</head>


<body>

<div id="PageWrapper" class="AdminRewrite">

<?php require(ABSPATH . '/system-admin/lyceum-header.php'); ?>

	<hr />

	<!-- BEGIN: body -->
	<div id="BodyWrapper">

		<!-- BEGIN: main column -->
		<div id="MainColumn">

			<!-- BEGIN: main nav -->
			<ul id="MainNav">
				<li><span><a href="settings.php">System Settings</a></span></li>
				<li><span><a href="blog-management.php">Blogs</a></span></li>
				<li><span><a href="user-management.php">Users</a></span></li>
				<li><span><a href="systemplugins.php">Plugins</a></span></li>
				<li class="Selected"><span><a href="rewriterules.php">Apache Rewrite Rules</a></span></li>
			</ul>
			<div class="ClearFix TabBorder"><!-- do not remove --></div>
			<!-- END: main nav -->

			<div class="wrap">
				<h2>mod_rewrite Config</h2>

				<h3>Via .htaccess file</h3>

				<div id="htaccess-status">
<?php if (file_exists(get_home_path() . '.htaccess')): ?>
					<p><strong>.htaccess file present</strong></p>

					<form action="rewriterules.php" method="post">
						<?php echo tokeninput('rewriterules.php', 'delete')?>

						<input type="hidden" name="action" value="delete" />

						<input type="submit" value="Delete .htaccess file" />
					</form>
<?php else: ?>
					<p><strong>.htaccess file NOT present</strong></p>
<?php endif; ?>

					&nbsp;&nbsp;&nbsp;

					<form action="rewriterules.php" method="post">
						<?php echo tokeninput('rewriterules.php', 'write')?>

						<input type="hidden" name="action" value="write" />

						<input type="submit" value="Write .htaccess file" />
					</form>
				</div>


				<h3>Manual Configuration</h3>

				<p>If you would like to put the mod_rewrite rules directly into your Apache configuration, here is the block of code to use (you probably want to delete your .htaccess file):</p>
				<p><em>Note: if any part of the path to src/lyceum is a symbolic link, then Apache might not be happy with the path in &lt;Directory ... &gt;. Use the path to the symbolic link instead.</em></p>

				<pre>
<?php
//$rules = explode("\n", $wp_rewrite->mod_rewrite_rules());
$rules = $wp_rewrite->mod_rewrite_rules();
$rules = '&lt;Directory "' . ABSPATH . '" &gt;' . "\n" . $rules . "\n" . '&lt;/Directory&gt;';
echo $rules;
?>
				</pre>

			</div>

		</div>
		<!-- END: main column -->

	</div>
	<!-- END: body -->

	<hr />

<?php include(ABSPATH . 'wp-admin/admin-footer.php'); ?>
	
</div>


</body>

</html>
